/* 
 * File:   HttpPool.h
 * Author: tzl 
 *
 * Created on July 4, 2011, 9:19 AM
 */

#ifndef HTTPPOOL_H
#define	HTTPPOOL_H

#include "NetIoPool.h"
#include "Http.h"

using namespace LibBase;

class HttpFeedback;

class HttpConn {
public:
	HttpConn()
	{
		_feedback = NULL;
		_req = NULL;
	}

	~HttpConn();
	HttpResponseParser	_parser;
	class HttpFeedback*	_feedback;
	HttpReqBuilder*		_req;
};

class HttpFeedback {
public:
	virtual ~HttpFeedback() { }
	
	virtual void onResponse(const char* buf, size_t len) = 0;
	virtual void free()
	{
		delete this;
	}
};

class HttpPool: public NetEvent {
public:
	HttpPool();	
	virtual ~HttpPool();

	bool start();

	bool request(const sockaddr* addr, size_t addrlen, HttpReqBuilder* req,
		HttpFeedback* feedback);

protected:
	HttpPool(const HttpPool& orig)
	{
	}
	
	virtual bool onInit(FileObjPtr& file);
	virtual void onUninit(FileObject* file);
	virtual void onConnect(FileObjPtr& file, int errcod);
	virtual void onDataIn(FileObjPtr& file, NetBuff* buf);

private:
	NetIoPool		_ioPool;
};

#endif	/* HTTPPOOL_H */
